import java.util.Base64;

/**
 * 分析EP的原始字节
 */
public class AnalyzeEPBytes {
    
    private static final String EP_BASE64 = "qt0AJsNLEfayUx7S15jLfmQvMOpW6JJ+jCoxeXxn676R2OiN6xpLIQWSYe8ETFUF4+AaGrVY1wMCdyUPVaHM0J+8m+q/PUFgbiP3N8xSKQc4lIzzZuckbybYiFuLbEhcblmy162S5B70UJxzB6grhIVpsG/h0uw+JPaS2yTPpPVCiN/SImdOw2g12cun6niAwRZSQktZikzzbjwkRoiO8ehrwlAFJircnT1/1zba2oaGXLc/yU6cM2vWgJdyyoXJF4Mo/5XNBTDT+8yr1hPC5MKHWcTBB/isrRTD5CczInLgXHl48KKz18GkpPM7MML1GHb4pIjfTvu8hv/SLLW0sg==";
    
    public static void main(String[] args) {
        try {
            System.out.println("=" + "=".repeat(99));
            System.out.println("分析EP字节");
            System.out.println("=" + "=".repeat(99));
            
            byte[] epBytes = Base64.getDecoder().decode(EP_BASE64);
            
            System.out.println("\nEP长度: " + epBytes.length + " 字节");
            System.out.println("\n完整EP字节 (hex):");
            
            for (int i = 0; i < epBytes.length; i++) {
                if (i % 16 == 0) {
                    System.out.printf("\n%04x: ", i);
                }
                System.out.printf("%02x ", epBytes[i] & 0xFF);
            }
            
            System.out.println("\n\n" + "=".repeat(100));
            System.out.println("检查PKCS1 Padding标记");
            System.out.println("=".repeat(100));
            
            // PKCS1 padding的前两个字节应该是 00 02 (加密) 或 00 01 (签名)
            System.out.printf("\n前4字节: %02x %02x %02x %02x\n", 
                epBytes[0] & 0xFF, epBytes[1] & 0xFF, epBytes[2] & 0xFF, epBytes[3] & 0xFF);
            
            // 如果ep确实是用NoPadding解密的PKCS1数据，那么解密后应该以00 02开头
            System.out.println("\n是否像PKCS1加密格式 (以00 02开头)? " + 
                (epBytes[0] == 0 && epBytes[1] == 2));
            
            System.out.println("是否像PKCS1签名格式 (以00 01开头)? " + 
                (epBytes[0] == 0 && epBytes[1] == 1));
            
            // 分析最高有效字节
            System.out.println("\n最高有效字节 (MSB): 0x" + String.format("%02x", epBytes[0] & 0xFF));
            
            // RSA加密的结果不应该以0x00开头，除非是padding
            if ((epBytes[0] & 0xFF) > 0x7F) {
                System.out.println("  MSB >= 0x80: 说明这是一个大整数，正常的RSA密文");
            } else if (epBytes[0] == 0) {
                System.out.println("  MSB = 0x00: 可能是padding标记或特殊情况");
            } else {
                System.out.println("  0 < MSB < 0x80: 这个值比较小");
            }
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


